'use strict';
/**
 * @fileoverview 联盟帮助，已帮助记录
 * @author sundbcn@gmail.com (sun debing)
 */

var mongoose = require('mongoose');
var moment = require('moment');
var _ = require('lodash');
var constantUtil = require('../util/constantUtil');
var dataApi = require('../libs/dataApi');

/**
 * 联盟帮助，已帮助记录
 */
var haveHelpSchema = new mongoose.Schema({
    // 角色Id
    role_id: {
        type: Number,
        required: true,
        index: true
    },

    // 标志id，唯一性
    only_id: {
        type: String,
        required: true,
        index: true
    },

    // 联盟id
    union_id: {
        type: Number,
        required: true,
        index: true
    },

    // 需要帮助 角色id
    require_role_id: {
        type: Number,
        required: true,
        index: true
    },

    // 共用id
    share_id: {
        type: Number,
        default: 0
    },

    // 帮助类型
    help_type: {
        type: Number,
        default: 0
    }

});

haveHelpSchema.pre('save', function (next) {
    this.increment();
    if (!this.isNew && !!this.isModified()) {
        this.pushModify();
    }
    next();
});

/**
 * 增加帮助任务
 * @return {[type]} [description]
 */
haveHelpSchema.methods.getUnion = function () {

};

/**
 * 获取修改
 * @return {[type]} [description]
 */
haveHelpSchema.methods.getLastChange = function () {
    return this.toJSON();
};

/**
 * 推送给用户
 * @return {[type]} [description]
 */
haveHelpSchema.methods.push = function () {
    this.pushModify();
};

haveHelpSchema.methods.pushModify = function () {

};

if (!haveHelpSchema.options.toJSON) {
    haveHelpSchema.options.toJSON = {};
}
/* jshint unused:false */
haveHelpSchema.options.toJSON.transform = function (doc, ret) {
    delete ret._id;
    delete ret.__v;
};

mongoose.model('HaveHelp', haveHelpSchema);
